package cn.dnf.system.controller;
import cn.dnf.basic.service.IPermissionScanService;
import cn.dnf.basic.util.JsonResult;
import cn.dnf.basic.util.PageList;
import cn.dnf.system.domain.Permission;
import cn.dnf.system.query.PermissionQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController // controller层，返回json格式数据
@RequestMapping("/permission")
@Api(value = "菜单的API",description="菜单相关的CRUD功能")
public class PermissionController {

    @Autowired
    private IPermissionScanService permissionService;






    /**
     *  分页数据
     * @return
     */
    @ApiOperation(value = "分页查询接口" )
    @PostMapping
    public PageList<Permission> queryPage(@RequestBody PermissionQuery query){
        try {
            // 哈哈哈
            return permissionService.pageQuery(query);
            // ....
            // .....
        } catch (Exception e) {
            e.printStackTrace();
            return new PageList<Permission>();
        }
    }


    /**
     * 批量删除
     * @param
     * @return
     */
    @PatchMapping()
    @ApiOperation(value = "批量删除" )
    public JsonResult patchDel(@RequestBody List<Long> ids){

        try {
            permissionService.patchDel(ids);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("网络延迟，稍后重试");
        }
    }
    /**
     * 查询所有信息
     * @return
     */
    @GetMapping
    public List<Permission> findAll(){
        return permissionService.loadAll();
    }



}
